const express = require('express')
const mongoose = require('mongoose')
//连接mongo 并且是用
const DB_URL = '';
mongoose.connect(DB_URL);
mongoose.connection.on('connected', function () {
  console.log('mongoose connect success');
})
mongoose.Connection.on('connected')
const User = mongoose.model('user', new mongoose.Schema({
  name: { type: String, require: true },
  age: { type: Number, require: true }
}))
User.create({
  name: 'xiaoming',
  age: 12
}, function (err, doc) {
  if (!err) {
    console.log(doc);
  } else {
    console.log(err)
  }
})
User.update({ name: 'xiaoming' }, { $set: { age: 24 } }, function () {

})

const User = mongoose.model('user', new mongoose.Schema())
//新建app
const app = express()

app.get('/', function (rep, res) {
  res.send('<h1>hello world</h1>')
})
app.get('/data', function (req, res) {
  User.find({}, function (err, doc) {
    res.json(doc)
  })
})
app.get('/data/more', (req, res) => {
  res.json({
    name: 'Jarry',
    age: 14
  })
})
app.listen(9093, function () {
  console.log('Node app start at 9093')
})